import 'package:flutter/material.dart';

class NavigatorDemo extends StatelessWidget {
  const NavigatorDemo({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FlatButton(
              child: Text('Home'),
              onPressed: () {
                Navigator.of(context).push(MaterialPageRoute(
                    builder: (BuildContext context) => Page(
                          title: "Home",
                        )));
              },
            ),
            FlatButton(
              child: Text('About'),
              onPressed: () {
                Navigator.pushNamed(context, '/about');
                // Navigator.push(context, MaterialPageRoute(builder: (context) {
                //   return Page(
                //     title: 'About',
                //   );
                // }));
                // Navigator.of(context).push(MaterialPageRoute(
                //     builder: (BuildContext context) => Page(
                //           title: "About",
                //         )));
              },
            )
          ],
        ),
      ),
    );
  }
}

class Page extends StatelessWidget {
  final String title;
  const Page({Key key, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        floatingActionButton: FloatingActionButton(
          backgroundColor: Colors.deepPurple,
          child: Icon(Icons.arrow_back),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
    );
  }
}
